package thread.localThread;

import java.util.Random;
/**
 * Created by 4790K_NSL on 2017/4/20.
 */
public class MyThreadLocalDataDemo {

    /**
     * The entry point of application.
     *
     * @param args the input arguments
     */
    public static void main(String[] args) {
        final MyThreadLocalDataDemo demo=new MyThreadLocalDataDemo();
        for (int i = 0; i < 3; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Integer i=new Random().nextInt();
                    demo.save(i);
                    System.out.println(Thread.currentThread() + " has save int of " +i);
                    System.out.println(Thread.currentThread() + " has loaded int of " + demo.load());;

                }
            }).start();
        }
    }

    /**
     * Load integer.
     *
     * @return the integer
     */
    public Integer load(){
        return MyThreadLocalData.getDataOfMyThread().get();

    }

    /**
     * Save.
     *
     * @param i the
     */
    public void save(Integer i){
        MyThreadLocalData.getDataOfMyThread().set(i);
    }
}
